//
//  HomeNewLSSViewController.m
//  shopping
//
//  Created by 马田成 on 2017/9/4.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "HomeNewLSSViewController.h"
#import "MineAddressRootViewController.h"
#import "zhiFuNewSSSViewController.h"
@interface HomeNewLSSViewController ()<UIWebViewDelegate,addressDelegate>
{
    
    UIWebView *myWebView;
    NSString *addressssID;
    NSString *addressStr;
    
    
}


@end

@implementation HomeNewLSSViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, scrWidth(), scrHeight())];
    //    myWebView.delegate = self;
    [self.view addSubview:myWebView];
    myWebView.delegate = self;
    myWebView.backgroundColor = [UIColor whiteColor];
    NSString *basePath = [[NSBundle mainBundle]bundlePath];
    NSString *helpHtmlPath = [basePath stringByAppendingPathComponent:@"newSell.html"];
    NSURL *url = [NSURL fileURLWithPath:helpHtmlPath];
    //加载本地html文件
    [myWebView loadRequest:[NSURLRequest requestWithURL:url]];
    // Do any additional setup after loading the view.
}


-(void)webViewDidFinishLoad:(UIWebView *)webView{
    
    NSString *jsStr = [NSString stringWithFormat:@"window.init.getToken('%@')",[PublicFunction getConfigWithKey:@"token"]];
    [myWebView stringByEvaluatingJavaScriptFromString:jsStr];
    
    
}


- (void)withString:(NSString *)addressID{
    
    addressssID = addressID;
    addressStr = [NSString stringWithFormat:@"test.hqaddressId('%@')",addressssID];
    [myWebView stringByEvaluatingJavaScriptFromString:addressStr];
    
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
    /**
     
     <!-- 自定义协议与OC进行交互 -->
     
     // 网页上的一个链接，点击这个链接出发以下反应。。。
     
     <a href="protocol:///showMessage"></a>
     <a href="protocol:///dingDan:订单id money:钱">女神</a>
     */
    
    //在此方法中截取下一个请求的URL,通过自定义协议头，截取要执行的方法和参数
    
    if ([request.URL.scheme isEqualToString:@"protocol"]) {
        
        //调用oc的方法做事
        
        //工作中用下面的
        
        NSArray *pathComponents = [request.URL pathComponents];
        
        //获取到方法名的字符串
        
        NSString *methodName = pathComponents[1];
        
        SEL method = NSSelectorFromString(methodName);
        
        if ([self respondsToSelector:method]) {
            
            [self performSelector:method];
        }else {
            
            NSArray *dingDan = [request.URL pathComponents];
            
            NSString *ding1 = dingDan[1];
            
            NSArray *array = [ding1 componentsSeparatedByString:@"money:"];
            NSArray *arrOfID = [array[0] componentsSeparatedByString:@"dingDan:"];
            
            NSArray *arrID = [arrOfID[1] componentsSeparatedByString:@","];
            
            NSLog(@"111111111111111%@", arrOfID[0]);
            [self dingDan:arrID[0] money:array[1]];
            
        }
        return NO;
        
    }
    
    
    return YES;
    
}

// OC的方法

- (void)showMessage{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}
- (void)dingDan:(NSString *)dingDan money:(NSString *)money{
    
    zhiFuNewSSSViewController *vc = [[zhiFuNewSSSViewController alloc] init];
    
    vc.orderId = dingDan;
    vc.money = money;
    
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)addressChange{
    
    MineAddressRootViewController *vc = [[MineAddressRootViewController alloc] init];
    vc.delegate = self;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
